
package com.example.paper.common.datam.migrate.job;

import java.util.UUID;

/**
 * TraceIdTL.
 *
 * @author Long Fengfan, 2022年03月14日

 */
public class TraceIdHolder {

    /**
     * 设置 TraceId 线程本地
     */
    private static final ThreadLocal<String> JobIdTL = ThreadLocal.withInitial(() -> UUID.randomUUID().toString());
    private static final ThreadLocal<Integer> ProcessIdTL = ThreadLocal.withInitial(() -> 0);

    private TraceIdHolder() {
    }

    /**
     * get方法获取对象
     *
     * @return ExceptionDetail
     */
    public static String getJobId() {
        return JobIdTL.get();
    }


    public static Integer getNextProcessId() {
        Integer integer = ProcessIdTL.get();
        integer++;
        ProcessIdTL.set(integer);
        return integer;
    }

    /**
     * 清除
     */
    public static void removeJobId() {
        JobIdTL.remove();
    }

    public static void removeProcessId() {
        ProcessIdTL.remove();
    }
}
